import java.util.Scanner;

/**
 * 查找两个字符串a,b中的最长公共子串i
 */
public class LongestCommonString {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String a = scanner.nextLine();
            String b = scanner.nextLine();
            if(a.length() > b.length()){
                longestString(b,a);
            }else {
                longestString(a,b);
            }
        }
    }

    private static void longestString(String a, String b) {
        int m = a.length()+1;
        int n = b.length()+1;
        int max = 0;
        int index = 0;
        int[][] dp = new int[m][n];

        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if(a.charAt(i-1) == b.charAt(j-1)){
                    dp[i][j] = dp[i-1][j-1] + 1;
                    if(dp[i][j] > max){
                        max = dp[i][j];
                        index = i;
                    }
                }
            }
        }
        System.out.println(a.substring(index-max,index));
    }
}
